package com.library.librarybackend.domain;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @author 平
 * @description 统一返回结果类
 * @since 2025-09-19 00:01
 */
@Data
@Accessors(chain = true)
public class Result<T> {

    private Integer code;

    private String message;

    private T data;

    public static <T> Result<T> from(ResponseStatus responseStatus) {
        Result<T> result = new Result<>();
        result.setCode(responseStatus.getCode());
        result.setMessage(responseStatus.getMessage());
        return result;
    }

    public static <T> Result<T> success() {
        return Result.from(ResponseStatus.SUCCESS);
    }

    public static <T> Result<T> success(T data) {
        return Result.<T>success().setData(data);
    }

    public static <T> Result<T> error() {
        return Result.from(ResponseStatus.ERROR);
    }

}
